package com.netposa.datawarehouse.statistics.service;

import com.netposa.vdt.pccclient.PccComputerClient;
import com.netposa.vdt.pccclient.common.ComputerState;
import com.netposa.vdt.pccclient.exception.PccHandleException;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang3.RandomUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PccService {
   private static final Logger log = LoggerFactory.getLogger(PccService.class);
   @Autowired
   PccComputerClient pccComputerClient;

   public Map computeState() throws PccHandleException {
      Map mock = new HashMap();
      mock.put("cpuInfo", new ComputerState(48.0, RandomUtils.nextDouble(15.0, 25.0), 0.0));
      mock.put("gpuInfo", new ComputerState(4.0, RandomUtils.nextDouble(0.8, 1.5), 0.0));
      return mock;
   }

   public Map taskCount() {
      Map retVal = new HashMap();

      try {
         retVal.put("already", this.pccComputerClient.allTaskCount());
         retVal.put("running", this.pccComputerClient.runTaskCount());
      } catch (Exception var3) {
         log.error(var3.getMessage(), var3);
         retVal.put("already", 100);
         retVal.put("running", 0);
      }

      return retVal;
   }
}
